package com.xiaohui.com.xiaohui.exception;


import com.xiaohui.com.xiaohui.bean.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {

    /**
     * 运行时异常
     */
    @ExceptionHandler({RuntimeException.class})
    public Result runtimeException(RuntimeException e) {
        e.printStackTrace();
        return Result.error(e.getMessage());
    }


    /**
     * 其他异常捕获
     */
    @ExceptionHandler({Exception.class})
    public Result exception(Exception exception) {
        exception.printStackTrace();
        return Result.error(exception.getMessage());
    }
}
